#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

list <int>a, b;

int get()
{
	int ans;

	if (a.empty()) {
		ans = b.front(); b.pop_front(); return ans;
	} else if (b.empty()) {
		ans = a.front(); a.pop_front(); return ans;
	} else if (a.front() > b.front()) {
		ans = b.front(); b.pop_front(); return ans;
	} else {
		ans = a.front(); a.pop_front(); return ans;
	}

}

int main(int artc, char *argv[])
{
	int n, i, p, sum;

	cin >> n;
	for (i=0; i<n; i++) {
		cin >> p;
		a.push_back(p);
	}

	a.sort();
	
	sum = 0;
	for (i=0; i<n-1; i++) {
		p = get() + get();
		b.push_back(p);
		sum += p;
	}

	cout << sum << endl;

	return 0;
}
